<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加供应商</title>
    <link rel="stylesheet" type="text/css" href="../../static/leftCommon.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/common.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/project.css"/>
</head>
<body>
    <div class="rightBox">
        <div class="documentName" style="margin-bottom: 50px;">供 应 商 重 新 评 价</div>
        <div class="surStep">
        
        </div>
    <!-- 公司详细信息 -->
        <div class="anewList">
            <!-- 需要填写打印的表格 -->
            <p class="anewsurList">供 方 重 新 评 价 表</p>
            <table id="List" cellspacing="0" cellpadding="0">
                <thead></thead>
                <tbody>
                    <!-- 第一行 -->
                    <tr>
                        <td class="interval">供方名称</td>
                        <td colspan="5">
                            <input type="text" class="sameInput" id="name">
                        </td>
                        <!-- <td>供方性质</td>
                        <td id="radio">
                            <label for="sc"><input type="radio" name="dan" id="sc">生产厂家</label>
                            <label for="lt"><input type="radio" name="dan" id="lt">流通领域</label>
                        </td> -->
                    </tr>
                    <!-- 第二行 -->
                    <tr>
                        <td class="interval">地址</td>
                        <td colspan="5"><input type="text" id="address" class="sameInput" autocomplete="off"></td>
                      
                    </tr>
                    <!-- 弹窗 -->
                    <!-- <div class="openWin">
                        <ul class="firNav">
                            
                        </ul>
                        <div class="secNav">
                            
                        </div>
                        <button type="button" id="btnS" style="position: absolute;right: 10px;bottom: 10px;">确认</button>
                    </div> -->
                        <!-- 部门id -->
                    <!-- <input type="hidden"  id="parentId" value="" />
                    <input type="hidden"  id="subId" value="" /> -->
                    <!-- 第三行 -->
                    <tr>
                        <td class="interval">联系人</td>
                        <td colspan="2"><input type="text" class="sameInput" id="liaison"></td>
                        <td class="interval">电话</td>
                        <td style="min-width:185px;" colspan="2"><input type="text" id="mobile" class="sameInput"></td>
                        
                    </tr>
                    <!-- 第四行 -->
                    <tr>
                        <td class="interval">应用物资及服务</td>
                        <td colspan="5" id="productName" style="text-align:left;text-indent: 20px;"></td>
                    </tr>
                    <!-- 第五行 -->
                    <tr>
                        <td class="interval">供方环境及安全内容</td>
                        <td colspan="5" id="envSafe" style="text-align:left;text-indent: 20px;"></td>
                    </tr>
                    <!-- 第六行 -->
                    <tr>
                        <td rowspan="2" class="interval">考核评价指标</td>
                        <td class="interval">供货质量情况(40分)</td>
                        <td class="interval">供货交付情况(10分)</td>
                        <td class="interval">售后服务质量(20分)</td>
                        <td class="interval">供货价格水平(30分)</td>
                        <td class="interval">总分</td>
                    </tr>
                    <tr>
                        <td><input type="text" class="sameInput" id="qualityScore"></td>
                        <td><input type="text" class="sameInput" id="deliveryScore"></td>
                        <td><input type="text" class="sameInput" id="afterSaleScore"></td>
                        <td><input type="text" class="sameInput" id="priceScore"></td>
                        <td><input type="text" class="sameInput" id="total" autocomplete="off"></td>
                    </tr>
                    <!-- 第七行 -->
                    <tr style="height:80px;" class="materialsComment none">
                        <td class="interval">物资部门意见</td>
                        <td colspan="5" style="height:120px;">
                            <textarea name="" id="materialsComment" style="width: 100%;height:80px;float: left; border: none; resize: none;"></textarea>
                            <input type="hidden" id="mater">
                        </td>
                    </tr>
                    <tr style="height:80px;" class="manageComment none">
                        <td class="interval">项目经理意见</td>
                        <td colspan="5" style="height:120px;">
                            <textarea name="" id="manageComment" style="width: 100%;height:80px;float: left; border: none; resize: none;"></textarea>
                            <input type="hidden" id="manage"> 
                        </td>
                    </tr>
                    <input type="hidden" id="status">
                </tbody>
            </table>
            <p style="text-align:center;margin: 20px 0;">
                <button type="button" class="submit btnBlue">提 交</button>
            </p>
        </div>
    </div>
</body>
</html>
<script src="../../static/js/jquery-1.8.3.js"></script>
<script src="../../static/dx.js"></script>
<script src="../../static/laydate/laydate.js"></script>
<script src="../static/js/progress.js"></script>
<script src="../static/js/comment.js"></script>
<script src="../static/js/tip.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    
    var id = DX.getParam('id');
    randerDetail(id);

    $('#qualityScore').change(function(){
        var qualityScore = $('#qualityScore').val() | 0;
        var deliveryScore = $('#deliveryScore').val() | 0;
        var afterSaleScore = $('#afterSaleScore').val() | 0;
        var priceScore = $('#priceScore').val() | 0;
        $('#total').val(qualityScore+deliveryScore+afterSaleScore+priceScore);
    })
    $('#deliveryScore').change(function(){
        var qualityScore = $('#qualityScore').val() | 0;
        var deliveryScore = $('#deliveryScore').val() | 0;
        var afterSaleScore = $('#afterSaleScore').val() | 0;
        var priceScore = $('#priceScore').val() | 0;
        $('#total').val(qualityScore+deliveryScore+afterSaleScore+priceScore);
    })
    $('#afterSaleScore').change(function(){
        var qualityScore = $('#qualityScore').val() | 0;
        var deliveryScore = $('#deliveryScore').val() | 0;
        var afterSaleScore = $('#afterSaleScore').val() | 0;
        var priceScore = $('#priceScore').val() | 0;
        $('#total').val(qualityScore+deliveryScore+afterSaleScore+priceScore);
    })
    $('#priceScore').change(function(){
        var qualityScore = $('#qualityScore').val() | 0;
        var deliveryScore = $('#deliveryScore').val() | 0;
        var afterSaleScore = $('#afterSaleScore').val() | 0;
        var priceScore = $('#priceScore').val() | 0;
        $('#total').val(qualityScore+deliveryScore+afterSaleScore+priceScore);
    })
})

function randerDetail(id){
   
   DX.ajax_method({
       'type':'GET',
       'url':'/materials/supply/supplierSurvey/findById',
       'param':{id:id},
       'callBack':function(res){
        //    console.log(res.data)
           doRander(res.data);
       }
   })
}
// 赋值渲染
function doRander(data){
 
    for(var j in data){
        if(!data[j] && data[j] != 0){
            data[j] = '';
        }else{
            for(var k in data[j]){
                if(!data[j][k] && data[j][k] != 0){
                    data[j][k] = '';
                }
            }
        }
    }
    // 流程
    $('.surStep').progress({
        active:0,
        data: [{
                title: '提交资料',
                date: getDate()
            },
            {
                title: '项目经理审核',
                date: ''
            },
            {
                title: '公司业务部门审核',
                date: ''
            }
        ]
    })

    // console.log(data)
//    $('#status').val(data.status);
    $('#name').val(data.supplier.name); 
    $('#address').val(data.supplier.addressProvince+data.supplier.addressSuffix);
    $('#liaison').val(data.liaison);
    $('#mobile').val(data.mobile);
    $('#envSafe').text(data.envSafe);
    $('#productName').text(data.product);



//    $('#qualityScore').val(data.qualityScore);
//    $('#deliveryScore').val(data.deliveryScore);
//    $('#afterSaleScore').val(data.afterSaleScore);
//    $('#priceScore').val(data.priceScore);
//    $('#total').val(data.qualityScore+data.deliveryScore+data.afterSaleScore+data.priceScore);



    // var status = data.status;
    // console.log(status)
    // if(status == 1){
    //     $('.materialsComment').removeClass('none');
    //     DX.ajax_method({
    //         'type':'GET',
    //         'url':'/emp/getLogUserInfo',
    //         'param':'',
    //         'callBack':function(res){
    //             $('#materialsComment').comment({
    //                 sign:res.data.name,
    //                 signDate:getDate(),
    //                 btnClick:function(status){
    //                    $('#mater').val(status ? 0 : 1);
    //                 }
    //             })
    //         }
    //     })
    // }else if(status == 2){
    //     $('.materialsComment').removeClass('none');
    //     $('.manageComment').removeClass('none');
    //     $('#materialsComment').comment({
    //         readonly:true,
    //         sign:data.materials.name,
    //         signDate:data.materialsCommentDate,
    //         signFile:data.materialsSignFile ? DX.domain('user')+'/user/file/img?size=80&fid='+data.materialsSignFile:null,
    //         signStatus:data.materialsCommentStatus, 
    //         content:data.materialsComment 
    //     })
    //     DX.ajax_method({
    //         'type':'GET',
    //         'url':'/emp/getLogUserInfo',
    //         'param':'',
    //         'callBack':function(res){
    //             $('#manageComment').comment({
    //                 sign:res.data.name,
    //                 signDate:getDate(),
    //                 btnClick:function(status){
    //                     $('#manage').val(status ? 0 : 1);
    //                 }
    //             })
    //         }
    //     })
    // }else{
    //     $('#materialsComment').comment({
    //         readonly:true,
    //         sign:data.materials.name,
    //         signDate:data.materialsCommentDate,
    //         signFile:data.materialsSignFile ? DX.domain('user')+'/user/file/img?size=80&fid='+data.materialsSignFile:null,
    //         signStatus:data.materialsCommentStatus, 
    //         content:data.materialsComment 
    //     })
    //     $('#manageComment').comment({
    //         readonly:true,
    //         sign:data.manage.name,
    //         signDate:data.manageCommentDate,
    //         signFile:data.manageSignFile ? DX.domain('user')+'/user/file/img?size=80&fid='+data.manageSignFile:null,
    //         signStatus:data.manageCommentStatus,
    //         content:data.manageComment
    //     })
    // }
}

//提交
$('.submit').click(function(){
    var url = '/materials/supply/supplierResurvey/insert';
    var obj = {};
    obj.surveyId = DX.getParam('id');
    obj.status = 1;
    obj.qualityScore = $('#qualityScore').val();
    obj.deliveryScore = $('#deliveryScore').val();
    obj.afterSaleScore = $('#afterSaleScore').val();
    obj.priceScore = $('#priceScore').val();
    var flag = true;
    if(DX.isNull(obj.qualityScore)){$('#qualityScore').tip({msg:'不可为空'});flag = false;}
    if(DX.isNull(obj.deliveryScore)){$('#deliveryScore').tip({msg:'不可为空'});flag = false;}
    if(DX.isNull(obj.afterSaleScore)){$('#afterSaleScore').tip({msg:'不可为空'});flag = false;}
    if(DX.isNull(obj.priceScore)){$('#priceScore').tip({msg:'不可为空'});flag = false;}
    if(!DX.isNumber(obj.qualityScore) || !DX.isInt(obj.qualityScore)){$('#qualityScore').tip({msg:'必须为正整数'});flag = false;}
    if(!DX.isNumber(obj.deliveryScore) || !DX.isInt(obj.deliveryScore)){$('#deliveryScore').tip({msg:'必须为正整数'});flag = false;}
    if(!DX.isNumber(obj.afterSaleScore) || !DX.isInt(obj.afterSaleScore)){$('#afterSaleScore').tip({msg:'必须为正整数'});flag = false;}
    if(!DX.isNumber(obj.priceScore) || !DX.isInt(obj.priceScore)){$('#priceScore').tip({msg:'必须为正整数'});flag = false;}
    if(obj.qualityScore > 40 || obj.qualityScore < 0){$('#qualityScore').tip({msg:'分数应在0-40之间'});flag = false;}
    if(obj.deliveryScore > 10 || obj.deliveryScore < 0){$('#deliveryScore').tip({msg:'分数应在0-10之间'});flag = false;}
    if(obj.afterSaleScore > 20 || obj.afterSaleScore < 0){$('#afterSaleScore').tip({msg:'分数应在0-20之间'});flag = false;}
    if(obj.priceScore > 30 || obj.priceScore < 0){$('#priceScore').tip({msg:'分数应在0-30之间'});flag = false;}
    if(!flag){return false;}


    // var url,obj = {id: DX.getParam('id')};
    // var status = $('#status').val();
    // if(status == 0){
    //     url = '/materials/supplierResurvey/insert';
    //     obj.status = 0;
    //     obj.qualityScore = $('#qualityScore').val();
    //     obj.deliveryScore = $('#deliveryScore').val();
    //     obj.afterSaleScore = $('#afterSaleScore').val();
    //     obj.priceScore = $('#priceScore').val();
    //     var flag = true;
    //     if(DX.isNull(obj.qualityScore)){$('#qualityScore').tip({msg:'不可为空'});flag = false;}
    //     if(DX.isNull(obj.deliveryScore)){$('#deliveryScore').tip({msg:'不可为空'});flag = false;}
    //     if(DX.isNull(obj.afterSaleScore)){$('#afterSaleScore').tip({msg:'不可为空'});flag = false;}
    //     if(DX.isNull(obj.priceScore)){$('#priceScore').tip({msg:'不可为空'});flag = false;}
    //     if(!flag){return false;}
    // }
    // if(status == 1){
    //     url = '/materials/supplierResurvey/addMaterialsComment';
    //     obj.status = $('#mater').val();
    //     obj.materialsComment = $('#materialsComment').val();
    // }
    // if(status == 2){
    //     url = '/materials/supplierResurvey/addManageComment';
    //     obj.status = $('#manage').val();
    //     obj.manageComment = $('#manageComment').val();
    // }
    // console.log(obj);
    var that = $(this);
    DX.ajax_method({
        'type':'POST',
        'url':url,
        'param':obj,
        'change':that[0],
        'callBack':function(res){
            console.log(res);
            if(res.code == 200){
                window.location.href = 'anew.html';
            }else{
                alert(res.msg);
            }
        }
    })
})

function getDate(){
    var now = new Date();
    var year = now.getFullYear(); //得到年份
    var month = now.getMonth();//得到月份
    var date = now.getDate();//得到日期
    month = month + 1;
    return year+'/'+month+'/'+date;
}
</script>